home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Utilities / Winter Shell 1.0d2 / Source / Libraries / FloatLib / FloatLib.c next >
Encoding:
C/C++ Source or Header  |  1994-01-07  |  893 b   |  43 lines  |  [TEXT/KAHL]

  1. /* floating point operations
  2.     93/12/24 aih created */
  3.  
  4. #include <SANE.h>
  5. #include "pstr.h"
  6. #include "FloatLib.h"
  7.  
  8. float FloatFromString(const CStr31 str)
  9. {
  10.     Str31 pstr;
  11.     extended exnum;
  12.     long double ldnum;
  13.     
  14.     c2pstrcpy(pstr, str);
  15.     #if defined(THINK_C) && !__option(mc68881) && __option(native_fp)
  16.         /* see THINK C 5.0 User Manual, p215 */
  17.         ldnum = str2num(pstr);
  18.     #else
  19.         exnum = str2num(pstr);
  20.         x80tox96(&exnum, &ldnum);
  21.     #endif
  22.     return(ldnum);
  23. }
  24.  
  25. void FloatToString(float num, CStr31 str, short precision)
  26. {
  27.     decform form;
  28.     extended exnum;
  29.     long double ldnum;
  30.  
  31.     ldnum = num;
  32.     form.style = 1; /* 0 = " 1.0e+0", 1 = "1.00" */
  33.     form.digits = precision;
  34.     #if defined(THINK_C) && !__option(mc68881) && __option(native_fp)
  35.         /* see THINK C 5.0 User Manual, p215 */
  36.         num2str(&form, num, str);
  37.     #else
  38.         x96tox80(&ldnum, &exnum);
  39.         num2str(&form, exnum, str);
  40.     #endif
  41.     p2cstr((StringPtr) str);
  42. }
  43.